<?php
include '../JHeader.php';
require_once('../Database/Database.php');

/*
 * LIVE-Überprüfung
 */
$response = '';
if(isset($_GET['q']) && isset($_GET['val']) && isset($_GET['shortcut']))
{
    $query    = $_GET['q'];
    $val      = $_GET['val'];
    $shortcut = $_GET['shortcut'];

    $db = new Database();
    $db->Connect();
    if($query == 'steam')
    {
        $series = $db->Select($shortcut . '_drivers', 'Steamname = \'' . $val . '\'');
        if($series)
        {
            $response = 'Name ist bereits vergeben!';
        }
        else
        {
            $response = 'OK';
        }
    }
    else if($query == 'checkteam')
    {
        $teams = $db->Select($shortcut . '_teams', 'Name = \'' . $val . '\'');
        if($teams)
        {
            $response = 'Name ist bereits vergeben!';
        }
        else
        {
            $response = 'OK';
        }
    }
    else if($query == 'team')
    {
        $teams = $db->Select($shortcut . '_teams', 'ID_Team = ' . $val);

        if($teams)
        {
            $response  = '<b>' . $teams[0]->Name . '</b><br />';
            $response .= 'Passwort: <input type="password" size=15 />';
        }
        else
        {
            $response = 'Konnte das Team nicht finden.';
        }
    }
    else if($query == 'vehicle' && isset($_GET['shortcut']))
    {
        $vehicles = $db->Select($_GET['shortcut'] . '_vehicles', 'ID_Vehicle = ' . $val);

        if($vehicles)
        {
            $response  = '<b>' . $vehicles[0]->Name . '</b><br />';
            $response .= 'Motor: ' . $vehicles[0]->Engine . '<br />';
            $response .= 'PS: '    . $vehicles[0]->Engine_Power . '<br />';
            $response .= 'RPM: '   . $vehicles[0]->RPM . '<br />';
        }
        else
        {
            $response = 'Konnte das Fahrzeug nicht finden.';
        }
    }
    else
    {
        $response = 'ERROR';
    }
    $db->Disconnect();
}
else
{
    $response = 'ERROR';
}

echo $response;
?>